import { SRaceRoom } from "../../../../Message/Public/SRaceRoom";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
//class RaceCopyRoomItem
    
    export  class RaceCopyRoomItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            this._btnEnter.addEventListener(flash.events.MouseEvent.CLICK, this.clickEnterHandler);
            return;
        }

        public get data(): SRaceRoom
        {
            return this._data;
        }

        /* internal  */clickEnterHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._data == null) 
            {
                return;
            }
            if (this._data.isStart) 
            {
                return;
            }
            if (this._data.playerNum >= this._data.maxPlayerNum) 
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.RaceCopyEnterCopy, this._data));
            return;
        }

        public setNotOpened(): void
        {
            this._txtIndex.text = "";
            this.enabled = false;
            this._txtPlayerNum.text = "";
            this._txtStatus.htmlText = Language.getString(80150);
            return;
        }

        public updateView(arg1: SRaceRoom): void
        {
            if (arg1 == null) 
            {
                return;
            }
            this._data = arg1;
            this._txtIndex.text = arg1.roomId.toString();
            var loc1=this._data.playerNum.toString() + "/" + this._data.maxPlayerNum.toString();
            this._txtPlayerNum.text = Language.getStringByParam(80145, loc1);
            if (this._data.isStart) 
            {
                this._txtStatus.htmlText = Language.getString(80148);
                this.enabled = false;
            }
            else if (this._data.playerNum >= this._data.maxPlayerNum) 
            {
                this._txtStatus.htmlText = Language.getString(80147);
                this.enabled = false;
            }
            else 
            {
                this._txtStatus.htmlText = Language.getString(80146);
                this.enabled = true;
            }
            this._btnEnter.enabled = true;
            return;
        }

        /* internal  */set enabled(arg1: Boolean)
        {
            this._btnEnter.enabled = arg1;
            this._btnEnter.mouseEnabled = arg1;
            this._btnEnter.mouseChildren = arg1;
            return;
        }

        /* internal  */initView(): void
        {
            this._btnEnter = ObjCreate.createGLoadedButton(ResFileConst.SkyCityBtn, 5, 5, 105, 106, this);
            var loc1=new GTextFormat(FontUtil.EmbedNumberName, 50, 16776960);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtIndex = ObjCreate.createGTextField("", 0, 10, 105, 52, this);
            this._txtIndex.embedFonts = true;
            this._txtIndex.defaultTextFormat = loc1;
            this._txtIndex.mouseEnabled = false;
            this._txtPlayerNum = ObjCreate.createGTextField("", 26, 60, 150, 20, this, GlobalStyle.textFormat6);
            this._txtPlayerNum.mouseEnabled = false;
            this._txtStatus = ObjCreate.createGTextField("", 32, 80, 100, 20, this, GlobalStyle.textFormat7);
            this._txtStatus.mouseEnabled = false;
            return;
        }

        /* internal */ /* var */_data: SRaceRoom;

        /* internal */ /* var */_txtIndex: GTextFiled;

        /* internal */ /* var */_txtPlayerNum: GTextFiled;

        /* internal */ /* var */_txtStatus: GTextFiled;

        /* internal */ /* var */_btnEnter: GLoadedButton;
    }
